﻿using System;
using System.Collections.Generic;

using Web.Generics;

using BolaoDNA.DomainModel;
using BolaoDNA.Repositories;

namespace BolaoDNA.Services
{
	public class InscricaoBolaoService : GenericService<InscricaoBolao> {
		private readonly IInscricaoBolaoRepository repository;
		public InscricaoBolaoService(IInscricaoBolaoRepository repository, ILogger logger) : base(repository, logger)
		{
			this.repository = repository;
		}

        public IList<InscricaoBolao> SelectByFilters(InscricaoBolao inscricaoBolao)
        {
            return this.repository.Select(new FilterParameters {
                FilterConditions = new [] {
                    new FilterCondition { Property="Bolao.ID", Comparer = FilterCondition.ComparerType.eq, Value=inscricaoBolao.Bolao.ID },
                    new FilterCondition { Property="UsuarioCadastrado.ID", Comparer = FilterCondition.ComparerType.eq, Value=inscricaoBolao.UsuarioCadastrado.ID },
                }
            });
        }

        public IList<InscricaoBolao> TrazerRanking(Bolao bolao, int qtdTop)
        {
            return this.repository.Select(new FilterParameters
            {
                FilterConditions = new [] {
                    new FilterCondition { Property="Bolao.ID", Comparer = FilterCondition.ComparerType.eq, Value = bolao.ID }
                },
                PageSize = qtdTop,
                PageIndex = 1,
                SortProperty = "PontuacaoTotal",
                SortOrder = FilterParameters.SortOrderEnum.Descending
            });
        }
    }
}
